package com.uvnos4j.matilda.schedule;

import com.uvnos4j.matilda.schedule.task.ScheduleTask01;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 定时任务枚举值
 * <p>
 * Description:定时任务枚举值 注：key 需要与数据库保持一致
 * </p>
 *
 * @author Guo.wl
 * @version v1.0.0
 * @since 2020-04-06 16:19:32
 */
public enum ScheduleTaskEnum {

    /**
     * 任务1
     */
    TASK_01("scheduledTask01", new ScheduleTask01()),
    ;

    /**
     * 定时任务key
     */
    private String taskKey;

    /**
     * 定时任务 执行实现类
     */
    private ScheduleTaskJob scheduledTaskJob;

    ScheduleTaskEnum(String taskKey, ScheduleTaskJob scheduledTaskJob) {
        this.taskKey = taskKey;
        this.scheduledTaskJob = scheduledTaskJob;
    }

    /**
     * 初始化 所有任务
     */
    public static Map<String, ScheduleTaskJob> initScheduledTask() {
        Map<String, ScheduleTaskJob> scheduledTaskJobMap = new ConcurrentHashMap<>();
        for (ScheduleTaskEnum taskEnum : ScheduleTaskEnum.values()) {
            scheduledTaskJobMap.put(taskEnum.taskKey, taskEnum.scheduledTaskJob);
        }
        return scheduledTaskJobMap;
    }

}